﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace CRM_2013
{
    public partial class lessonsEditForm : DevExpress.XtraEditors.XtraForm
    {

        public Guid idParent;
        public bool isMain;
        public Guid idNew;
        public string nameParentLesson;
        
        public lessonsEditForm()
        {
            InitializeComponent();
        }

        private void lessonsEditForm_Load(object sender, EventArgs e)
        {
            
            this.usersTA.Fill(this.dataSet2.Users);
            this.productTA.Fill(this.dataSet2.Product);
            this.lessonsTA.Fill(this.dataSet2.Lessons);

            bsLessons.AddNew();

            if (isMain)
            {
                labelControl1.Text = "Добавление нового тренинга";
            }
            else
            {
                labelControl1.Text = "Занятие для тренинга '"+nameParentLesson+"'";
            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            bsLessons.CancelEdit();
            bsLessons.RemoveCurrent();
            this.Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {

            Guid id = Guid.NewGuid();
            ((DataRowView)bsLessons.Current)["idLessons"] = id;
            idNew = id;
            
            ((DataRowView)bsLessons.Current)["isPast"] = 0;
            if (isMain)
            {
                ((DataRowView)bsLessons.Current)["ref_Lessons"] = DBNull.Value;
                ((DataRowView)bsLessons.Current)["IsMain"] = 1;
            }
            else
            {
                ((DataRowView)bsLessons.Current)["ref_Lessons"] = idParent;
                ((DataRowView)bsLessons.Current)["IsMain"] = 0;
            }

            bsLessons.EndEdit();
            lessonsTA.Update(dataSet2.Lessons);
            this.Close();
        }
    }
}